<?php


namespace app\common\cachemodel;


use app\common\model\BaseCache;
use think\Exception;
use XznsTools\cache\CacheManage;

/**
 * 系统配置模型
 * Class SystemConfig
 * @package app\common\cachemodel
 */
class SystemConfig extends BaseCache
{
    protected $table = 'wechatadmin.system_system';

    protected $cacheModel = 'config.system';

    /**
     * 获取配置信息
     * @param $filed array
     * @return array|bool|mixed
     * @throws \Exception
     */
    public function getSystemConfig($filed = [])
    {
        $config = CacheManage::getInstance()->setCacheConfig($this->cacheModel)->getDataAndSet(function ()
        {
            return $this->getConfigByDb();
        }, $filed);

        return $config;
    }

    /**
     * 从缓存中获取配置信息
     * @return array|mixed
     */
    protected function getConfigByDb()
    {
        try
        {
            $data = $this->where('name', 'site_config')->value('value');

            $config = unserialize($data);
        }
        catch (Exception $e)
        {
            $config = [];
        }

        return $config;
    }
}
